home *** CD-ROM | disk | FTP | other *** search
/ Fritz: All Fritz / All Fritz.zip / All Fritz / FILES / PROGNG_C / QBLIBGV.LZH / QDEMO.C next >
Text File  |  1987-07-11  |  17KB  |  392 lines

  1. /************************************************************************/
  2. /************************************************************************//*
  3.  
  4.  
  5.                   QLIB DEMONSTRATION PROGRAM
  6.  
  7.      This program exercises the QLIB functions for TUBBO C (the name
  8.      "TURBO C" is the property of BORLAND INTERNATIONAL).
  9.  
  10.      To run this program, specify QDEMO.PRJ as the project file and
  11.      ajust your compiler options to a LARGE MEMORY MODEL.
  12.  
  13.      To become a registered QLIB user, see the comments at the end
  14.      of this file.
  15.  
  16.      For additional information, run the QWELCOME.COM program.
  17.                                                                         */
  18. /************************************************************************/
  19. /************************************************************************/
  20.  
  21.  
  22.  
  23. /************************************************************************/
  24. /***************  beginning of QDEMO declaration block  *****************/
  25. /************************************************************************/
  26.  
  27. /*  declaration for the strings to be processed by qlib variables    */
  28. typedef     unsigned     char    string[79];
  29.  
  30. /*  declaration for the prompt structure, see comments below for more    */
  31. /*  information on the qlib prompt conventions.                */
  32. typedef struct    prompt_structure
  33.         {
  34.         string    tag;
  35.         string    value;
  36.         int    tagx;
  37.         int     tagy;
  38.         int    valx;
  39.         int    valy;
  40.         int    vall;
  41.         char    tagf;
  42.         char    tagb;
  43.         char    valf;
  44.         char    valb;
  45.         int    valr;
  46.         string  valt;
  47.         string  vale;
  48.         char    prmx;
  49.         string  mhea;
  50.         string  mtra;
  51.         string  stid;
  52.         int    poid;
  53.         } prompt_record;
  54.  
  55. /************************************************************************/
  56. /*                 beginning of mainline demo program                */
  57. /************************************************************************/
  58. main()
  59. {
  60. /*  initialize some color attributes to be used in the demo        */
  61. unsigned    char    red            = 4;
  62. unsigned    char    white_on_blue  = 31;
  63. unsigned    char    black_on_white = 112;
  64. unsigned    char    bright_white   = 15;
  65. unsigned    char    blinking_white = 143;
  66. unsigned    char    blinking_blue  = 129;
  67. unsigned    char    cyan_on_blue   = 27;
  68.  
  69. /*  declare a variable "anystring" to be of type "string"        */
  70. string        anystring;
  71.  
  72. /*  declare a variable "q" to be of type "prompt_record"        */
  73. prompt_record    q;
  74.  
  75. /*  declare some general integer variables                */
  76. int index;
  77. int intvar;
  78. int returnkey = 13;
  79. int f1key = 0x013b;
  80. int f2key = 0x013c;
  81. int f3key = 0x013d;
  82.  
  83. char charvar;
  84.  
  85. /*  set up and print welcome screen, see the functions below for comments */
  86. /*  and notes on individual functions used here...                        */
  87.     qclrscr(bright_white);
  88.     qdrawbox(0, 7, 79, 12,
  89.         "[ QLIB DEMONSTRATION PROGRAM ]",
  90.         "[ HIT          TO COMTINUE ]",
  91.         white_on_blue,
  92.         bright_white,
  93.         bright_white);
  94.     qsetatt(1,8,78,11,cyan_on_blue);
  95.     qsnap("<RETURN>", 32, 12, blinking_white);
  96.     qcenter_line("A set of easy to use, flexible, consistent, well-documented", 9, white_on_blue);
  97.     qcenter_line("functions for TURBO C", 10, white_on_blue);
  98.     qgotoxy(0,25);
  99.     while(! (intvar==returnkey) )
  100.         {
  101.         intvar=qreadkbd();
  102.         }
  103. /*  end of welcome screen...                                            */
  104.  
  105. /*           beginning of commented code                                */
  106.  
  107. /*  the following line uses the qclrscr function to clear the screen     */
  108. /*  and set the default attribute to bright white (15d).        */    
  109.         qclrscr(bright_white);
  110.  
  111. /*  the following line positions the cursor at column 0, row 0        */
  112.     qgotoxy(0, 0);
  113.  
  114. /*  set up variables for printf                      */
  115.     strcpy(anystring,"this is an output line");
  116.     printf("We are going to output some characters using printf - hit a key when ready...\n");
  117.     charvar = getch();
  118.  
  119.     qclrscr(bright_white);
  120.     qgotoxy(0, 0);
  121.     for (index=1;index<25;++index)  printf("%s\n", anystring);
  122.  
  123. /*  the following line uses the qgotoxy function to "hide" the cursor, */
  124. /*  the technique recommended by MICROSOFT.                            */
  125.     qgotoxy(0, 25);
  126.  
  127. /*  the following line uses the qsnap function to print the literal    */
  128. /*  at column 0, row 24.  The literal will be printed in blinking cyan  */
  129. /*  on blue.                                */
  130.     qsnap("hit <return> to go on...", 0, 24, cyan_on_blue + 0x80);
  131.  
  132.     charvar = getch();
  133.     qclrscr(bright_white);
  134.     qcenter_line("Did you notice that I turned the cursor off?", 10, bright_white);
  135.     qcenter_line("Now we do twice that with qlib calls - hit a key when ready...", 12, bright_white);
  136.     charvar = getch();
  137.     qclrscr(bright_white);
  138.  
  139. /*  the following line uses the qrembox function to clear the screen.    */
  140.     qrembox(0, 24, 79, 24);
  141.  
  142.     for (index=0;index<24;++index)  qsnap(anystring, 00, index, bright_white);
  143.     for (index=0;index<24;++index)  qsnap(anystring, 50, index, bright_white);
  144.     qrembox(0, 9, 79, 10);
  145.  
  146. /*  the following line uses the qcenter function to center the literal    */
  147. /*  on line 9 of an 80 column screen.  It will be centered in bright     */
  148. /*  white (15d).                            */
  149.     qcenter_line("That was it!!!", 9, bright_white);
  150.  
  151.     qcenter_line("just hit any key to continue", 10, blinking_white);
  152.     charvar = getch();
  153.     qclrscr(bright_white);
  154.  
  155. /*  the following line sets the default attribute from column 0, row 11,*/
  156. /*  to column 79, row 13, to white on blue.                */
  157.     qsetatt(0,11,79,13,white_on_blue);
  158.  
  159.     qcenter_line("ok - now for some boxes...  hit a key when ready", 12, white_on_blue);
  160.     charvar = getch();
  161.     qclrscr(bright_white);
  162.  
  163. /*  the following line draws a box on the screen from column 17, row 0, */
  164. /*  to column 79, row 5.  The box characters will be bright white.    */
  165. /*  The first literal will be centered between column 17 and column 79    */
  166. /*  on row 0 and will be black on white.  The second literal will be    */
  167. /*  centered between column 17 and column 79 on row 5 and will be cyan    */
  168. /*  on blue.  The area inside the box will be cleared.            */                                
  169.         qdrawbox(17, 00, 79, 05, "[ THIS IS ANOTHER BOX ]", "[ BOTTOM TITLE ]", bright_white, black_on_white, cyan_on_blue);
  170.  
  171.     qdrawbox(00, 00, 15, 05, "[ HELLO ]", "", bright_white, black_on_white, 0);
  172.         qdrawbox(00, 07, 45, 11, "[ THIS IS A SQUISHY BOX ]", "[ DIMENSIONS ARE 0,7,45,11 ]", white_on_blue, black_on_white, black_on_white);
  173.         qdrawbox(47, 07, 79, 23, "[ THIS IS A LONG BOX ]", "[ THIS IS LINE 23 ]", 13, 14, 15);
  174.     qdrawbox(00, 13, 05, 23, "", "", 11, 15, 15);
  175.     qdrawbox(06, 13, 10, 23, "", "", cyan_on_blue, 15, 15);
  176.     qdrawbox(11, 13, 45, 23, "", "", 14, 15, 15);
  177.     qsnap("hit <return>...", 0, 24, blinking_white);
  178.     charvar = getch();
  179.     qclrscr(bright_white);
  180.     qclrscr(15);
  181.  
  182. /*  The following line clears out the keyboard buffer.            */
  183.     qdrain_keyboard();
  184.  
  185.     charvar = 0;
  186.     qcenter_line("keyboard status display", 0, 15);
  187.     qcenter_line("please play with <ALT>, <CTRL>, <R-SHFT>, <L-SHFT>,", 5, 15);
  188.     qcenter_line("<CAPS>, <INSERT>, <NUM>, and <SCROLL>", 6, 15);
  189.     qcenter_line("press <return> to quit...", 10, 15);
  190.     qgotoxy(0,25);
  191.     intvar = 0;
  192.     while(intvar != returnkey)
  193.         {
  194.         while (!kbhit())
  195. /*              The following line displays the key board    */
  196. /*              status (toggles) on line 24.            */
  197.             qkbd_status_line(24);
  198.  
  199. /*  The following line calls the qreadkbd function.  Upon return, the    */
  200. /*  high byte of "intvar" will contain a one if a special key has been  */
  201. /*  pressed (function keys, arrow keys, etc).  If a special key has not */
  202. /*  been pressed, the high byte of "intvar" will contain a zero.  In    */
  203. /*  either case, the low byte of "intvar" will contain the ascii code   */
  204. /*  representing the keystroke.  The QLIB functions qhi(intvar), and    */
  205. /*  qlo(intvar) can be used to segregate the bytes into unsigned char   */
  206. /*  variables if need be.                        */
  207.         intvar = qreadkbd();
  208.  
  209. /*  The loop exit conditions are intvar==13, which translates to hitting*/
  210. /*  the <return key>.                                      */
  211.         }
  212.         qdrain_keyboard();
  213.         qclrscr(cyan_on_blue);
  214.     qdrawbox(0, 9, 79, 11, "", "", 14, 22, 0);
  215.     qcenter_line("What about prompts?  Hit any key to continue...", 10, 23);
  216.     charvar = getch();
  217.      qclrscr(bright_white);
  218.  
  219. /*----------------------------------------------------------------------*/
  220. /*  The following segment of code intializes a "prompt record" in    */
  221. /*  preparation for a call to the qprompt function.            */
  222. /*                                                                      */
  223. /*    A "prompt" is considered to have the following elements:          */
  224. /*                                                                      */
  225. /*       (Elements included in release 3)                               */
  226. /*            tag   -  A literal describing the data to be collected    */
  227. /*            value -  The data to be collected                         */
  228. /*            tagx  -  The column where the tag is to be displayed      */
  229. /*            tagy  -  The row where the tag is to be displayed         */
  230. /*            tagf  -  The foreground color to be used when displaying  */
  231. /*                     the tag                                          */
  232. /*            tagb  -  The background color to be used where displaying */
  233. /*                     the tag                                          */
  234. /*            valx  -  The column where data collection is to begin     */
  235. /*            valy  -  The row where data collection is to occur        */
  236. /*            vall  -  The maximum number of characters to be collected */
  237. /*            valf  -  The foreground color of characters entered       */
  238. /*            valb  -  The background color of characters entered       */
  239. /*                                                                      */
  240. /*       (Elements not included in release 3)                           */
  241. /*            valr  -  The edit rules mask for entered characters       */
  242. /*            valt  -  The external table to be used for validation     */
  243. /*            vale  -  The external table to be used for expansion      */
  244. /*            mhea  -  The message header string                        */
  245. /*            mtra  -  The message trailer string                       */
  246. /*            stid  -  The destination LAN station                      */
  247. /*            poid  -  The destination port                             */
  248. /*            prmx  -  The exit conditions mask                         */
  249. /*----------------------------------------------------------------------*/
  250.         
  251. /*  The following line initializes the prompt tag                        */
  252.     strcpy(q.tag, "Type a string for me to center or <return> to quit:  ");
  253.  
  254. /*  The following line intializes the column where the prompt tag is to */
  255. /*  be displayed.                            */
  256.     q.tagx = 0;
  257.  
  258. /*  The following line initializes the row where the prompt tag is to   */
  259. /*  be displayed.                            */
  260.     q.tagy = 5;
  261.  
  262. /*  The following line sets the foreground color for the prompt tag.    */
  263.     q.tagf = 15;
  264.  
  265. /*  The following line sets the background color for the prompt tag.    */
  266.     q.tagb = 0;
  267.  
  268. /*  The following line sets the first column where the string is to be    */
  269. /*  collected.                                */
  270.     q.valx = q.tagx + strlen(q.tag);
  271.  
  272. /*  The following line sets the row where the string is to be collected */
  273.     q.valy = q.tagy;
  274.  
  275. /*  The following line sets the maximum length of the string to be     */
  276. /*  collected.                                */
  277.     q.vall = 25;
  278.  
  279. /*  The following lines sets the foreground color for the string as it  */
  280. /*  is entered.                                */
  281.     q.valf = 7;
  282.  
  283. /*  The following lines sets the background color for the string as it  */
  284. /*  is entered.                                */
  285.     q.valb = 1;
  286.  
  287. /*  The following initializes the data itself                */
  288.     strcpy(q.value, "      ");
  289.  
  290.     qcenter_line("THE QLIB FUNCTIONS ACT TOGETHER TO CREATE PROMPTS!", 16, bright_white);
  291.     while (strlen(q.value) != 0)
  292.         {
  293.  
  294. /*        The following line sends the prompt record to the prompt*/
  295. /*        function.  On return, the element "value" will contain  */
  296. /*        what was entered at the keyboard.              */
  297.  
  298.         qprompt(&q);
  299.         qrembox(0, 0, 79, 0);
  300.         qcenter_line(q.value, 0, 15);    
  301.         }
  302.  
  303.         qclrscr(bright_white);
  304.     qcenter_line("Let's play with the          keys", 12, 15);
  305.     qsnap("FUNCTION", 43, 12, cyan_on_blue + 0x80);
  306.     qcenter_line("Please hit the F9 key to continue...", 14, 15);
  307.     qgotoxy(0,25);
  308.     intvar = 0;
  309.     while(! (intvar==0x0143) ) /* 0x0143 is how qreadkbd() returns F9 */
  310.         intvar = qreadkbd();
  311.     qcenter_line("THE QLIB FUNCTIONS ACT TOGETHER TO CREATE MENUS!!!!", 5, bright_white);
  312.     while(! (intvar==f3key) )
  313.         {
  314.         qdrawbox(19,10,59,18,"[ MAIN MENU ]","[ QDEMO FUNCTIONS ]", cyan_on_blue, black_on_white, red);
  315.         qcenter_line("F1           Do this           ", 13, bright_white);
  316.         qcenter_line("F2           Do the other thing", 14, bright_white);
  317.         qcenter_line("F3           Quit              ", 15, bright_white);
  318.         qcenter_line("PRESS F1, F2, or F3 ", 23, bright_white);
  319.         qrembox(0,24,79,24);
  320.         qdrain_keyboard();
  321.         intvar=qreadkbd();
  322.         qcenter_line("   INVALID CHOICE   ", 23, blinking_white);
  323.         if (intvar==f1key)
  324.             {
  325.             qcenter_line("   You selected F1  ", 23, blinking_white);
  326.             qcenter_line("F1           Do this           ", 13, black_on_white);
  327.             }
  328.         if (intvar==f2key)
  329.             {
  330.             qcenter_line("   You selected F2  ", 23, blinking_white);
  331.              qcenter_line("F2           Do the other thing", 14, black_on_white);
  332.             }
  333.         qcenter_line("Hit <RETURN> to continue", 24, bright_white);
  334.         if (intvar != f3key) while(! (intvar==returnkey)) intvar = qreadkbd();
  335.                 }
  336.         qclrscr(bright_white);
  337.     for (index=0;index<=24;++index)
  338.         qcenter_line("Thank you  Thank you  Thank you  Thank you", index, index);
  339.     qdrawbox(10, 8, 70, 12, "[ QLIB DEMONSTRATION PROGRAM ]", "[ THAT'S ALL FOLKS! ]", bright_white, bright_white, bright_white);
  340.     qcenter_line("Become a registered user today!", 10, bright_white);
  341.     qgotoxy(0,23); }
  342. /*---------------------  end of program  ----------------------------------*/
  343. /*
  344.         In addition to complete documentation, QLIB registrants will
  345.         receive new releases of QLIB for one year mailed automatically
  346.         with no further action required on your part.  New releases
  347.         (at least one is guaranteed) will be sent on low density (360K)
  348.         diskettes.  Documentation will be included on the diskette
  349.         and with laser-jet quality hard copy.    
  350.  
  351.         The registration process involves sending your name, address,
  352.         Compuserve ID (if appropriate), and $35 to:
  353.  
  354.                       Lisa T. Vass
  355.                       5311 Blvd East # 3
  356.                       West New York, New Jersey  07093
  357.  
  358.         Non domestic registrants must include an additional $20.
  359. */
  360.  
  361. /***************************************************************************/
  362. /*                                                                         */
  363. /*   below is a sample of the documentation sent to qlib registrants       */
  364. /*                                                                         */
  365. /***************************************************************************//*
  366. qsnap function:
  367.  
  368.     usage:  void qsnap (unsigned char string[79],
  369.                 unsigned int x,
  370.                             unsigned int y,
  371.                             unsigned char attribute);
  372.         location:           qlib.lib
  373.         related functions:  void qget (unsigned char string[79],
  374.                                        unsigned int x,
  375.                                        unsigned int y,
  376.                                        unsigned int length);
  377.         description:        Qsnap provides no-snow, direct screen output.
  378.                     the assumed screen dimensions are 0 - 79
  379.                     columns (the "X" variable) and 0 - 24 rows
  380.                             (the "Y" variable).
  381.                             Qget returns a string of specified length
  382.                             from column x, row y.  Terminating the
  383.                             string with an ASCII zero for any subsequent
  384.                             string processing is the programmer's
  385.                             responsibility.
  386.     returns:            Nothing.  No error checking.  Integer variables
  387.                             are used to permit access to "invisible" rows
  388.                             and columns.  This usage, however, is not
  389.                             supported or recommended, other than for hiding
  390.                             the cursor (column 0, row 25) */
  391. /*-------------------------------------------------------------------------*/
  392.